//
//  LBViewController.m
//  LBTILiveSDK
//
//  Created by 刘文扬 on 03/13/2018.
//  Copyright (c) 2018 刘文扬. All rights reserved.
//

#import "LBViewController.h"
#import <LBTILiveSDK/LBAVBaseView.h>

#import <LBAlert.h>

#import "LBDiscussAVTopView.h"

@interface LBViewController ()

/** avView*/
@property(nonatomic,strong)LBAVBaseView *avView;


@end

@implementation LBViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self.view addSubview:self.avView];

    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    __weak LBViewController *weakSelf = self;
    [LBAlert showInputTextFieldWithMessage:nil limit:20 placeholder:@"房间号" buttons:@[@"取消",@"确定"] block:^(LBAlertInputTextField *input, NSInteger answer) {
        if (answer == 0) {
            
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }else{
            weakSelf.title = input.textField.text;
            [weakSelf startPlayWithRoomId:input.textField.text];
        }
    }];
    
    

    
    
	// Do any additional setup after loading the view, typically from a nib.
}

-(void)startPlayWithRoomId:(NSString *)roomId
{
    self.avView.role = LBAVRoleHost;
    self.avView.roomId = roomId;
    NSMutableArray *ownSides = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < 1; ++i) {
        LBAVMemberModel *model = [LBAVMemberModel new];
        [ownSides addObject:model];
    }
    
    self.avView.ownSideMembers = ownSides;
    
    //传入占位空的数组
    NSMutableArray *otherSides = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < 3; ++i) {
        LBAVMemberModel *model = [LBAVMemberModel new];
        [otherSides addObject:model];
    }
    self.avView.otherSideMembers = otherSides;
    [self.avView startDisplay];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

-(LBAVBaseView *)avView
{
    if (_avView == nil) {
        
        _avView = [[LBAVBaseView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, self.view.frame.size.height)];
        LBDiscussAVTopView *topView = [[LBDiscussAVTopView alloc] init];
        [topView updateData];
        _avView.lb_topView = topView;
    }
    return _avView;
}


-(void)dealloc
{
    [[LBTILiveManager shareManager] releaseResouce];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
